﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using PHMEE.Admin.Controllers;
using PHMEE.ToolKits;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace PHMEE.Admin.HttpApi.Controllers.BaseInfo.Vessels
{
    /// <summary>
    /// 基础信息管理🚢🌞🌛✨
    /// </summary>
    [Route("phmeeadmin/api")]
    public class VesselController : PHMEEAdminController
    {
        private readonly IVesselAppService vesselAppService;

        /// <summary>
        /// 构造器注入
        /// </summary>
        /// <param name="vesselAppService"></param>
        public VesselController(IVesselAppService vesselAppService)
        {
            this.vesselAppService = vesselAppService;
        }

        #region 船舶API


        /// <summary>
        /// 创建船舶
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("vessel/CreateVessel")]
        public async Task<Guid> CreateVessel(VesselCreateDto input)
        {
            return await vesselAppService.CreateVesselAsync(input);

        }

        /// <summary>
        /// 更新船舶
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        [Route("vessel/UpdateVessel")]
        public async Task UpdateVessel(VesselUpdateDto input)
        {
            await vesselAppService.UpdateVesselAsync(input);

        }

        /// <summary>
        /// 删除船舶
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        [Route("vessel/DeleteVessel")]
        public async Task DeleteVessel(Guid id)
        {
            await vesselAppService.DeleteVesselAsync(id);
        }

        /// <summary>
        /// 船舶详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("vessel/GetVesselById")]
        public async Task<VesselDto> GetVesselById(Guid id)
        {
            return await vesselAppService.GetVesselByIdAsync(id);
        }

        /// <summary>
        /// 船舶分页集合
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("vessel/GetPagedVessels")]
        public async Task<PagedResultDto<VesselDto>> GetPagedVessels(VesselListDto input)
        {
            return await vesselAppService.GetPagedVesselsAsync(input);

        }

        /// <summary>
        /// 船舶类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("vessel/GetVesselTypes")]
        public List<OperationOptionInt> GetVesselTypes(Guid? id)
        {
            return vesselAppService.GetVesselTypes(id);
        }

        /// <summary>
        /// 流量计模式
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("vessel/GetVesselFlowMeterModes")]
        public List<OperationOptionInt> GetVesselFlowMeterModes(Guid? id)
        {
            return vesselAppService.GetVesselFlowMeterModes(id);
        }

        /// <summary>
        /// 批量创建机组初始化
        /// </summary>
        /// <param name="vesselIds"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("vessel/GetVesselUnitInitialRows")]
        public async Task<List<VesselBatchTree>> GetVesselUnitInitialRows(List<Guid> vesselIds)
        {
            return await vesselAppService.GetVesselUnitInitialRows(vesselIds);
        }

        /// <summary>
        /// 批量创建机组
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("vessel/BatchVesselUnitRows")]
        public async Task BatchVesselUnitRows(List<VesselBatchTree> rows)
        {
            await vesselAppService.BatchVesselUnitRows(rows);
        }


        #endregion

        #region 机组API

        /// <summary>
        /// 创建机组
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("unit/CreateUnit")]
        public async Task<Guid> CreateUnit(UnitCreateDto input)
        {
            return await vesselAppService.CreateUnitAsync(input);
        }

        /// <summary>
        /// 更新机组
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        [Route("unit/UpdateUnit")]
        public async Task UpdateUnit(UnitUpdateDto input)
        {
            await vesselAppService.UpdateUnitAsync(input);


        }

        /// <summary>
        /// 删除机组
        /// </summary>
        /// <param name="id"></param>
        /// <param name="vesselId"></param>
        /// <returns></returns>
        [HttpDelete]
        [Route("unit/DeleteUnit")]
        public async Task DeleteUnit(Guid id, Guid vesselId)
        {
            await vesselAppService.DeleteUnitAsync(id, vesselId);

        }

        /// <summary>
        /// 机组详情
        /// </summary>
        /// <param name="id"></param>
        /// <param name="vesselId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("unit/GetUnitById")]
        public async Task<UnitDto> GetUnitById(Guid id, Guid vesselId)
        {
            return await vesselAppService.GetUnitByIdAsync(id, vesselId);

        }

        /// <summary>
        /// 机组分页集合
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("unit/GetPagedUnits")]
        public async Task<PagedResultDto<UnitDto>> GetPagedUnits(UnitListDto input)
        {
            return await vesselAppService.GetPagedUnitsAsync(input);
        }

        /// <summary>
        /// 机组类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("unit/GetUnitTypes")]
        public List<OperationOptionInt> GetUnitTypes(Guid? id)
        {
            return vesselAppService.GetUnitTypes(id);
        }


        /// <summary>
        /// 机组类型初始化值
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("unit/GetUnitInitDefaultProperties")]
        public Dictionary<string, object> GetUnitInitDefaultProperties(UnitEnum type)
        {
            return vesselAppService.GetUnitInitDefaultProperties(type);
        }

        #endregion

        #region 设备API

        /// <summary>
        /// 创建设备
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("equipment/CreateEquipment")]
        public async Task<Guid> CreateEquipment(EquipmentCreateDto input)
        {
            return await vesselAppService.CreateEquipmentAsync(input);

        }

        /// <summary>
        /// 更新设备
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        [Route("equipment/UpdateEquipment")]
        public async Task UpdateEquipment(EquipmentUpdateDto input)
        {
            await vesselAppService.UpdateEquipmentAsync(input);

        }

        /// <summary>
        /// 删除设备
        /// </summary>
        /// <param name="id"></param>
        /// <param name="vesselId"></param>
        /// <param name="unitId"></param>
        /// <returns></returns>
        [HttpDelete]
        [Route("equipment/DeleteEquipment")]
        public async Task DeleteEquipment(Guid id, Guid vesselId, Guid unitId)
        {
            await vesselAppService.DeleteEquipmentAsync(id, vesselId, unitId);

        }

        /// <summary>
        /// 设备详情
        /// </summary>
        /// <param name="id"></param>
        /// <param name="vesselId"></param>
        /// <param name="unitId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("equipment/GetEquipmentById")]
        public async Task<EquipmentDto> GetEquipmentById(Guid id, Guid vesselId, Guid unitId)
        {
            return await vesselAppService.GetEquipmentByIdAsync(id, vesselId, unitId);
        }

        /// <summary>
        /// 设备分页详情
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("equipment/GetPagedEquipments")]
        public async Task<PagedResultDto<EquipmentDto>> GetPagedEquipments(EquipmentListDto input)
        {
            return await vesselAppService.GetPagedEquipmentsAsync(input);

        }

        /// <summary>
        /// 设备类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("equipment/GetEquipmentTypes")]
        public async Task<List<OperationOptionInt>> GetEquipmentTypes(Guid? id, Guid vesselId, Guid unitId)
        {
            return await vesselAppService.GetEquipmentTypes(id, vesselId, unitId);
        }

        /// <summary>
        /// 设备转动方式
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("equipment/GetEquipmentRotationModes")]
        public List<OperationOptionInt> GetEquipmentRotationModes()
        {
            return vesselAppService.GetEquipmentRotationModes();
        }

        /// <summary>
        /// 设备基座类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("equipment/GetEquipmentConnectModes")]
        public List<OperationOptionInt> GetEquipmentConnectModes()
        {
            return vesselAppService.GetEquipmentConnectModes();
        }

        /// <summary>
        /// 设备支撑方式
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("equipment/GetEquipmentSupportFlexibilityModes")]
        public List<OperationOptionInt> GetEquipmentSupportFlexibilityModes()
        {
            return vesselAppService.GetEquipmentSupportFlexibilityModes();
        }

        /// <summary>
        /// 设备轴承类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("equipment/GetEquipmentBearingTypes")]
        public List<OperationOptionInt> GetEquipmentBearingTypes()
        {
            return vesselAppService.GetEquipmentBearingTypes();
        }

        #endregion

        #region 部件API    

        /// <summary>
        /// 创建部件
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("component/CreateComponent")]
        public async Task<Guid> CreateComponent(ComponentCreateDto input)
        {
            return await vesselAppService.CreateComponentAsync(input);

        }

        /// <summary>
        /// 更新部件
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        [Route("component/UpdateComponent")]
        public async Task UpdateComponent(ComponentUpdateDto input)
        {
            await vesselAppService.UpdateComponentAsync(input);

        }

        /// <summary>
        /// 删除部件
        /// </summary>
        /// <param name="id"></param>
        /// <param name="vesselId"></param>
        /// <param name="unitId"></param>
        /// <param name="equipmentId"></param>
        /// <returns></returns>
        [HttpDelete]
        [Route("component/DeleteComponent")]
        public async Task DeleteComponent(Guid id, Guid vesselId, Guid unitId, Guid equipmentId)
        {
            await vesselAppService.DeleteComponentAsync(id, vesselId, unitId, equipmentId);
        }

        /// <summary>
        /// 部件详情
        /// </summary>
        /// <param name="id"></param>
        /// <param name="vesselId"></param>
        /// <param name="unitId"></param>
        /// <param name="equipmentId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("component/GetComponentById")]
        public async Task<ComponentDto> GetComponentById(Guid id, Guid vesselId, Guid unitId, Guid equipmentId)
        {
            return await vesselAppService.GetComponentByIdAsync(id, vesselId, unitId, equipmentId);
        }

        /// <summary>
        /// 部件分页详情
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("component/GetPagedComponents")]
        public async Task<PagedResultDto<ComponentDto>> GetPagedComponents(ComponentListDto input)
        {
            return await vesselAppService.GetPagedComponentsAsync(input);

        }

        /// <summary>
        /// 部件类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("component/GetComponentTypes")]
        public async Task<List<OperationOptionInt>> GetComponentTypes(Guid? id, Guid vesselId, Guid unitId, Guid equipmentId)
        {
            return await vesselAppService.GetComponentTypes(id, vesselId, unitId, equipmentId);
        }

        #endregion

        #region 基础信息层级结构

        /// <summary>
        /// 机组层级结构
        /// </summary>
        /// <param name="unitId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("level/GetUnitRelation")]
        public async Task<VesselRelationDto> GetUnitRelation(Guid unitId)
        {
            return await vesselAppService.GetUnitRelation(unitId);
        }

        /// <summary>
        /// 设备层级结构
        /// </summary>
        /// <param name="equipmentId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("level/GetEquipmentRelation")]
        public async Task<VesselRelationDto> GetEquipmentRelation(Guid equipmentId)
        {
            return await vesselAppService.GetEquipmentRelation(equipmentId);
        }

        /// <summary>
        /// 部件层级结构
        /// </summary>
        /// <param name="componentId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("level/GetComponentRelation")]
        public async Task<VesselRelationDto> GetComponentRelation(Guid componentId)
        {
            return await vesselAppService.GetComponentRelation(componentId);
        }

        /// <summary>
        /// 基础信息层级结构
        /// </summary>
        /// <param name="includePoints"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("level/GetBaseInfoTree")]
        public async Task<List<VesselTree>> GetBaseInfoTree(bool includePoints)
        {
            return await vesselAppService.GetBaseInfoTree(includePoints);
        }

        /// <summary>
        /// 基础信息层级标签
        /// </summary>
        /// <param name="ownerType"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("level/GetBaseInfoTags")]
        public List<OperationOptionInt> GetBaseInfoTags(string? ownerType)
        {
            return vesselAppService.GetBaseInfoTags(ownerType);
        }

        /// <summary>
        /// 基础信息层级编号1-20
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("level/GetBaseInfoNumbers")]
        public List<OperationOptionInt> GetBaseInfoNumbers()
        {
            return vesselAppService.GetBaseInfoNumbers();
        }

        #endregion

    }
}
